package cn.edu.ldu.protocol;

import cn.edu.ldu.modules.controller.GroupChatController;
import cn.edu.ldu.modules.entity.GroupChatEntity;
import cn.edu.ldu.util.Consts;
import cn.edu.ldu.views.modules.controller.UserController;
import com.alibaba.fastjson.JSONObject;

public class GetChatGroup {

    public GetChatGroup(Protocol protocol){

        Long groupId = Long.valueOf(JSONObject.parseObject(protocol.getData()).getString("id"));

        try {
            GroupChatEntity groupChatEntity = GroupChatController.getGroupChat(groupId, protocol.getToken());
            if(groupChatEntity == null){
                protocol.setData(null);
                protocol.setKey("不存在该群聊");
                UserController.sendDataToUser(protocol);
            }else {
                protocol.setData(JSONObject.toJSONString(groupChatEntity));
                protocol.setKey(Consts.P_GROUP_RESULT);
                UserController.sendDataToUser(protocol);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
